package com.doubleTwist.androidPlayerTest;

import java.util.List;

import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.jayway.android.robotium.solo.Solo;

@SuppressWarnings("unchecked")
public class TestAPK extends ActivityInstrumentationTestCase2 {
	private static final String TARGET_PACKAGE_ID = "com.doubleTwist.androidPlayer"; // CHANGE
	private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.doubleTwist.androidPlayer.HomePagerActivity"; // CHANGE
	private static Class launcherActivityClass;
	static {
		try {
			launcherActivityClass = Class
					.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}

	public TestAPK() throws ClassNotFoundException {
		super(TARGET_PACKAGE_ID, launcherActivityClass);
	}

	private Solo solo;

	@Override
	protected void setUp() throws Exception {
		solo = new Solo(getInstrumentation(), getActivity());
	}

//	public void testPlaySongWMA() {
//		solo.sleep(1000); // wait for splash
//		solo.clickOnText("Titel"); // select songs
//		solo.sleep(2000);
//		solo.clickInList(2); // first item wma
//		solo.clickOnImage(3);	//bring the controls to the front
//		solo.sleep(5000); // playing 5sec
//		solo.clickOnImage(12);	//pause
////		for (int i = 1; i < 20; i++) {
////			solo.clickOnImage(i);
////			Log.d("own", i + "");
////			solo.sleep(2000);
////		}
//		// Log.d("own", solo.getCurrentImageButtons().size() + "");
//		// solo.clickOnView(solo.getCurrentImageViews().get(5));
//		// solo.clickOnView(solo.getCurrentImageViews().get(10));
//		// Toast.makeText(null, "You chose: ", Toast.LENGTH_LONG).show();
//		// List<ImageView> btnList = solo.getCurrentImageViews();
//		// for (int i = 0; i < btnList.size(); i++) {
//		// ImageView btn = btnList.get(i);
//		// solo.clickOnView(btn);
//		// }
//		solo.sleep(1000); // wait before exit
//	}

//	 public void testPlaySongMP3() {
//		solo.sleep(1000); // wait for splash
//		solo.clickOnText("Titel"); // select songs
//		solo.sleep(2000);
//		solo.clickInList(3); // second item mp3
//		solo.clickOnImage(3);	//bring the controls to the front
//		solo.sleep(5000); // playing 5sec
//		solo.clickOnImage(12);	//pause
//		solo.sleep(1000); // wait before exit
//	 }
	
	 public void testNextSong() {
		solo.sleep(1000); // wait for splash
		solo.clickOnText("Titel"); // select songs
		solo.sleep(2000);
		solo.clickInList(3); // second item mp3
		solo.clickOnImage(3); // bring the controls to the front
		solo.sleep(5000); // playing 5sec
		solo.clickOnImage(13);	//next song
		solo.sleep(5000); // playing 5sec
		solo.clickOnImage(11);	//pause
		solo.sleep(1000); // wait before exit
	 }
	
	// public void testPlaylistCreate() {

	// }

	 //public void testPlaylistDelete() {

	// }

	// public void testEqualizer() {

	// }

	// public void testPlaySongMP3WithHeadsetPlugIn() {

	// }

	@Override
	public void tearDown() throws Exception {
		solo.finishOpenedActivities();
	}
}